//
//  MainViewController.swift
//  SinaWeibo
//
//  Created by nyan on 6/12/16.
//  Copyright © 2016 nyan. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
       var mainTabBar =  MainTabBar()
        
        setValue(mainTabBar, forKey: "tabBar")
        
        mainTabBar.composeBtn.addTarget(self, action: "composeDidClick", forControlEvents: .TouchUpInside)


        //
        addChildViewControllers()
    }
    private func addChildViewControllers(){
        
        addChildViewController(HomeTableViewController(), title: "Home", imageName: "tabbar_home")
         addChildViewController(MessageTableViewController(), title: "Message", imageName: "tabbar_message_center")
         addChildViewController(DiscoverTableViewController(), title: "Discover", imageName: "tabbar_discover")
         addChildViewController(ProfileTableViewController(), title: "me", imageName: "tabbar_profile")
    }
    
    private func addChildViewController(vc:UIViewController, title: String,imageName: String ) {
//    let home  = HomeTableViewController()
    self.tabBar.tintColor = UIColor.orangeColor()
        
    let nav = UINavigationController(rootViewController: vc)
    nav.title = title
    vc.title =  title

    vc.tabBarItem.image = UIImage(named: imageName)
    vc.tabBarItem.selectedImage = UIImage(named: imageName + "_highlighted")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
//    vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.orangeColor()], forState: UIControlState.Selected)
    addChildViewController(nav)
    
       }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    func composeDidClick() {
        print("mayuyu")
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
